package com.gjzt.business.publish.listener;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.runtime.ProcessInstance;

import com.eastdigit.bpm.service.FormFactory;
import com.eastdigit.system.service.SpringServiceFactory;
import com.gjzt.business.publish.inter.PublishBillMapper;
import com.gjzt.business.publish.model.PublishBill;
import com.gjzt.business.publish.service.PublishBillService;
import com.gjzt.business.utils.Constant;

public class AuditAgreeListener implements ExecutionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2502235078719201313L;

	@Override
	public void notify(DelegateExecution execution) throws Exception {
		String processInstanceId = execution.getProcessInstanceId();
		ProcessInstance processInstance = execution.getEngineServices()
				.getRuntimeService().createProcessInstanceQuery()
				.processInstanceId(processInstanceId).singleResult();
		String businessKey = processInstance.getBusinessKey();
		String billId = FormFactory.getBusinessId(businessKey);
		PublishBillMapper publishBillMapper = (PublishBillMapper)SpringServiceFactory.getBean("publishBillMapper");
		
		PublishBill publishBill = new PublishBill();
		publishBill.setBillId(billId);
    	publishBill.setStatus(Constant.PUBLISH_BILL_STATUS_AUDIT_TRUE);
    	publishBillMapper.updateByPrimaryKeySelective(publishBill);
    	
    	PublishBillService publishBillService = (PublishBillService)SpringServiceFactory.getBean("publishBillService");
    	publishBillService.createMmakeBill(billId);

	}

}
